<!-- message dialog box -->
<div id="msgDialog"><p></p></div>

<script type="text/template" id="readTemplate">
        <tr id="${receipt_id}">
                <td align="center" width="30px">${nomor}</td>
                <td style="text-align:left;">${receipt_date}</td>
				<td style="text-align:left;">${custom_receipt_id}</td>
                <td style="text-align:left;">${getNikName}</td>
				
                <td align= "center" width="110px">
					<a class="" href="<?=base_url().'index.php/receipt/topdf/' . '${receipt_id}' . '/' . '${territory_id}'?>">PDF</a> | 
					<a class="" href="<?=base_url().'index.php/receipt/getDetail/' . '${receipt_id}' . '/' . '${territory_id}'?>">Detail</a>		
				</td>
				
        </tr>

</script>

<script type="text/javascript">
var readUrl   = 'index.php/receipt/read';

$( function() {
    
    $( '#tabs' ).tabs({
        fx: { height: 'toggle', opacity: 'toggle' }
    });
    
    readUsers();
    
    $( '#msgDialog' ).dialog({
        autoOpen: false,
        
        buttons: {
            'Ok': function() {
                $( this ).dialog( 'close' );
            }
        }
    });    
    
  
}); //end document ready


function readUsers() {
    //display ajax loader animation
    $( '#ajaxLoadAni' ).fadeIn( 'slow' );
    
	var tempId = "", row = "";
    $.ajax({
        url: readUrl,
        dataType: 'json',
        success: function( response ) {
            var j=1;
            for( var i in response ) {
                response[ i ].nomor = j;
				
				//generate custom receipt_id
				// tempId = response[ i ].receipt_id;
                //defog
                // added by: alfin akhret
                var tempId;
                $.ajax({
                              url: "<?=base_url();?>index.php/receipt/defoger",
                              type: "POST",
                              data: {'str' : response[ i ].receipt_id},
                              dataType: 'json',
                              async: false,
                              success: function(response2) {
                               
                                tempId = response2;
                                
                              }
                       });

				if (tempId.toString().length < 8)
				{
					var ii = tempId.toString().length;
					for(ii; ii<8; ii++)
					{
						tempId = '0' + tempId;
					}
				}
				response[ i ].custom_receipt_id = tempId;
                j++;
            }
            
            //clear old rows
            $( '#records > tbody' ).html( '' );
            
            //append new rows
            $( '#readTemplate' ).render( response ).appendTo( "#records > tbody" );
			
            //apply dataTable to #records table and save its object in dataTable variable
            if( typeof dataTable == 'undefined' )
                dataTable = $( '#records' ).dataTable({"bJQueryUI": true});
            
            //hide ajax loader animation here...
            $( '#ajaxLoadAni' ).fadeOut( 'slow' );
        }
    });
} // end readUsers
</script>